﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using ScrumPilot.TFSHelpers;
using TeamFoundation = Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace ScrumPilot.Domain.Models
{
    public interface IIWorkItem
    {
        int ID { get; set; }
        Nullable<Int32> AssignedToID { get; set; }
        string AssignedTo { get; set; }
        void CompleteInit(TeamFoundation.WorkItem wie, TFSServices tfs,Boolean inSameIteration);
    }

    public class WorkItemProject
    {
        public int ID { get; set; }
        public String Url { get; set; }
        public string Name { get; set; }
        public string CurrentSprint { get; set; }
        public int Workers { get; set; }
        public int TotalScore { get; set; }
        public int TotalCompletedScore { get; set; }
        public decimal EstimatedTime { get; set; }
        public decimal RemainingTime { get; set; }
        public decimal CompletedTime { get; set; }
        public int RoundEstimatedTime { get { return (int)Decimal.Round(this.EstimatedTime); } }
        public int RoundCompletedTime { get { return (int)Decimal.Round(this.CompletedTime); } }
        public int TimeRatio
        {
            get
            {
                return (int)(EstimatedTime != 0 ? Decimal.Round((CompletedTime / EstimatedTime) * 100) : 0);
            }
        }
        public int ScoreRatio
        {
            get
            {
                decimal rate = TotalCompletedScore;
                if (TotalScore != 0)
                {
                    rate /= TotalScore;
                    rate *= 100;
                    return (int)(TotalScore != 0 ? Decimal.Round(rate) : 0);
                }
                return 0;
            }
        }

        public int TimeRatioColor { get; set; }
        public List<int> WorkItemClasses { get; set; }
        public List<int> UserStories { get; set; }
    }

    public class WorkItemClass
    {
        public int Count { get; set; }
        public int Time { get; set; }
        public string Name { get; set; }
        public WorkItemState State { get; set; }
    }

    public class WorkItem : IIWorkItem
    {
        [Key]
        public int ID { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public string ProjectName { get; set; }
        public Int32 ProjectID { get; set; }
        public Int32 AreaID { get; set; }
        public Int32 IterationID { get; set; }
        public string State { get; set; }
        public string Type { get; set; }
        public string ParentType { get; set; }
        public string ParentName { get; set; }
        public string ParentUrl { get; set; }
        public Nullable<Int32> AssignedToID { get; set; }
        public string AssignedTo { get; set; }
        public string Url { get; set; }
        public decimal RemainTime { get; set; }
        public decimal EstimatedTime { get; set; }
        public decimal CompletedTime { get; set; }
        public String CreatedBy { get; set; }
        public DateTime CreateDate { get; set; }
        public int Score { get; set; }
        public DateTime Date { get; set; }

        public List<TeamFoundation.Attachment> Attachments { get; set; }

        public string LastModifiedDate
        {
            get { return Date.ToString("f"); }
        }

        public string ISO8601Date
        {
            get { return Date.ToString("o"); }
        }

        public virtual void CompleteInit(TeamFoundation.WorkItem wie, TFSServices tfs,Boolean inSameIteration=false)
        {
            throw new NotImplementedException();
        }

    }
}
